<!Doctype html>
<html>
<head>
	<meta charset="utf-8" />
	<title></title>
	<style>
		#box,#box1{float:left;display:block;margin:10px;width:100px;height:100px;outline:1px solid #aaf;}
	</style>
</head>
<body>
	<input type="button" id="btn" value="开始计数">
	<input type="button" id="btn1" value="计数1"><br/>
	<div>
		<span id="box"></span><span id="box1"></span>
	</div>
	<script>
		var btn = document.getElementById('btn');
		var btn1 = document.getElementById('btn1');
		btn.onclick = doCount();
		btn1.onclick = doCount();
		function doCount(box){
			var timer;
			function countNumber(){
				clearInterval(timer);
				var i = 0;
				box = document.getElementById(box);
				function addon(){
					if(i>=5){
						clearInterval(timer);
					}else{
						i++;
						console.log(i);
					}
				}
				timer = setInterval(addon,500);
			}
			return countNumber;
		}
	</script>
</body>
</html>